package cn.com.lms.business.exam.service;
import cn.com.lms.business.exam.persistence.entity.PaperExtra;
import cn.com.lms.business.exam.persistence.repository.PaperExtraRepository;

import com.bnzj.core.persistence.BaseService;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Optional;

@Service
public class PaperExtraService extends BaseService<PaperExtraRepository, PaperExtra,Long> {




    @Transactional
    public PaperExtra savePaperExtra(Long paperId,Integer paperScore,Integer subjectCount){
        this.deleteByPaperId(paperId);
        PaperExtra paperExtra=new PaperExtra();
        paperExtra.setPaperId(paperId);
        paperExtra.setPaperScore(paperScore);
        paperExtra.setSubjectCount(subjectCount);
        return  super.save(paperExtra);
    }


    public void deleteByPaperId(Long paperId) {
        repository.deleteByPaperId(paperId);
    }

    public PaperExtra findByPaperId(Long paperId) {
        PaperExtra paperExtra=new PaperExtra();
        paperExtra.setPaperId(paperId);
        Optional<PaperExtra>  opt=super.findOne(paperExtra);
        if(opt.isPresent()){
            return opt.get();
        }
        return  null;
    }
}